/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

/**
 *
 * @author Vojtisek
 */
@Entity
public class BankTransaction implements Serializable, Comparable<BankTransaction> {

    private static final Long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    @ManyToOne
    private Account from;
    @ManyToOne
    private Account to;
    @Column(name = "amountFrom", scale = 2, precision = 10)
    private BigDecimal amountFrom;
    @Column(name = "amountTo", scale = 2, precision = 10)
    private BigDecimal amountTo;
    @Column(name = "amount", scale = 2, precision = 10)
    private BigDecimal amount;
    @Column(name = "TransferDate")
    private Date TransferDate;
    @Column(name = "TransferTime")
    private Time TransferTime;
    @ManyToOne
    private CurrencyEE currency;

    public BankTransaction() {
    }

    public BankTransaction(Account from, Account to, BigDecimal amount) {
        this.from = from;
        this.to = to;
        this.amount = amount;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public BigDecimal getAmountFrom() {
        return amountFrom;
    }

    public void setAmountFrom(BigDecimal amountFrom) {
        this.amountFrom = amountFrom;
    }

    public BigDecimal getAmountTo() {
        return amountTo;
    }

    public void setAmountTo(BigDecimal amountTo) {
        this.amountTo = amountTo;
    }

    public CurrencyEE getCurrency() {
        return currency;
    }

    public void setCurrency(CurrencyEE currency) {
        this.currency = currency;
    }

    public Account getFrom() {
        return from;
    }

    public void setFrom(Account from) {
        this.from = from;
    }

    public Account getTo() {
        return to;
    }

    public void setTo(Account to) {
        this.to = to;
    }

    public Date getTransferDate() {
        return TransferDate;
    }

    public void setTransferDate(Date TransferDate) {
        this.TransferDate = TransferDate;
    }

    public Time getTransferTime() {
        return TransferTime;
    }

    public void setTransferTime(Time TransferTime) {
        this.TransferTime = TransferTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BankTransaction)) {
            return false;
        }
        BankTransaction other = (BankTransaction) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Transaction[id=" + id + "]";
    }

    public int compareTo(BankTransaction o) {
        if (this.getId() < o.getId()) {
            return 1;
        }
        if (this.getId() > o.getId()) {
            return -1;
        }
        return 0;
    }
}
